﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FSToolkit.Demo
{
    public partial class MainForm : Form
    {
        const string VALUE = "Sensor wide";
        const string LEVEL = "Level";
        const string ID = "ID";
        const string TITLE = "Sensor wide vs.Level";
        readonly List<string> Levels = new List<string> { "1.5a", "1.5b", "2", "2c" };
        DataTable dt;
        public MainForm()
        {
            InitializeComponent();
        }

        private void GenerateRandomDataBtn_Click(object sender, EventArgs e)
        {
            var count = Levels.Count;
            var rd = new Random();
            if (dt != null)
                dt.Clear();
            dt = new DataTable(TITLE);
            dt.Columns.Add(VALUE, typeof(float));
            dt.Columns.Add(LEVEL, typeof(string));
            dt.Columns.Add(ID, typeof(string));
            for (var i = 0; i < 100; i++)
            {
                var v = rd.Next(0, count);
                dt.Rows.Add(rd.Next(200, 600) / 1000.0f, Levels[v], Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5));
            }
            dataGridView1.DataSource = dt;
        }

        private void DisChartBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var standard = new List<float> { 0.35f, 0.5f };
                scatterChartcs1.PlotParticles(dt, dt.TableName, LEVEL, VALUE, standard, Levels);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"图表显示异常：{ex.Message }");
            }
        }
    }
}
